####
# Copy MOSS and WAC bits over to WFE or APP machine
# Written By Nate Bruneau | IS Engineering Team
####

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

if ($env:mossnetworkpath -eq $null){
Write-Host -ForegroundColor Red '$env:mossnetworkpath variable was not found in your environment.ps1 config file. Please add it and re-run -Main'
$env:terminate = $true
exit 0
}
if ($env:wacnetworkpath -eq $null){
Write-Host -ForegroundColor Red '$env:wacnetworkpath variable was not found in your environment.ps1 config file. Please add it and re-run -Main'
exit 0 
}
if ($env:mosssetuppath -eq $null){
Write-Host -ForegroundColor Red '$env:mosssetuppath variable was not found in your environment.ps1 config file. Please add it and re-run -Main'
$env:terminate = $true
exit 0
}


## Copying over MOSS Bits to Server
	if (Test-Path "$env:mosssetuppath\MOSS"){
	Write-Host -ForegroundColor Yellow "CopyBits: MOSS Install Folder already exists. Continuing install..."
	}
	else
	{
	Write-Host "Copying MOSS bits locally to over to $env:mosssetuppath\MOSS from server path $env:mossnetworkpath ..."		
	Copy-Item $env:mossnetworkpath "$env:mosssetuppath\MOSS" -Recurse
	}
	
## Copying over WAC Bits to Server

	if ($env:installWAC -eq $false) {
	## do nothing if installWAC is set to False
	}
	else
	{
		## Copying over WAC Bits to Server
		if (Test-Path "$env:mosssetuppath\WAC"){
		Write-Host -ForegroundColor Yellow "CopyBits: WAC Install Folder already exists. Continuing install..."
		}
		else
		{
		Write-Host "Copying WAC bits locally to over to $env:mosssetuppath\WAC from server path $env:wacnetworkpath ..."		
		Copy-Item $env:wacnetworkpath "$env:mosssetuppath\WAC" -Recurse
		}
	}
